package com.anonymous.service.impl;

import com.anonymous.entity.Check;
import com.anonymous.dao.CheckDao;
import com.anonymous.service.CheckService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (Check)表服务实现类
 *
 * @author makejava
 * @since 2022-01-16 11:17:36
 */
@Service("checkService")
public class CheckServiceImpl implements CheckService {
    @Resource
    private CheckDao checkDao;

    /**
     * 通过ID查询单条数据
     *
     * @param checkId 主键
     * @return 实例对象
     */
    @Override
    public Check queryById(Integer checkId) {
        return this.checkDao.queryById(checkId);
    }

    /**
     * 分页查询
     *
     * @param check       筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<Check> queryByPage(Check check, PageRequest pageRequest) {
        long total = this.checkDao.count(check);
        return new PageImpl<>(this.checkDao.queryAllByLimit(check, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param check 实例对象
     * @return 实例对象
     */
    @Override
    public Check insert(Check check) {
        this.checkDao.insert(check);
        return check;
    }

    /**
     * 修改数据
     *
     * @param check 实例对象
     * @return 实例对象
     */
    @Override
    public Check update(Check check) {
        this.checkDao.update(check);
        return this.queryById(check.getCheckId());
    }

    /**
     * 通过主键删除数据
     *
     * @param checkId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer checkId) {
        return this.checkDao.deleteById(checkId) > 0;
    }
}
